/*
revamp ERRTHING.
just ERRTHING.
*/
var n;
if ((instance_exists(global.team_member_current_id) == true) and (global.cutscene == false) and (global.dialog == false))
{
    for (n = 0; n < array_length_1d(global.inventory_current_id); n++)
    {
        global.inventory_current_id[n] = (global.team_member_current_id).character_inventory_index[n];
    }
    global.inventory_current_maxitems = (global.team_member_current_id).character_inventory_maxitems;
    
    if (global.inventory == true)
    {
        //Exit the inventory screen
        if (keyboard_check_pressed(global.button[6]) == true)
        {
            global.inventory = false;
            global.control = 1;
        }
        //Use an inventory item (SHOULD BE OPEN THE ITEM OPTIONS MENU)
        if (keyboard_check_pressed(global.button[0]) == true)
        {
            inventory_item_use(inventory_selected);
        }
        //Equipping an item
        if (keyboard_check_pressed(global.button[3]) == true)
        {
            if (ds_list_find_value(global.inventory_current_id[0], inventory_selected) > 0)
            {
                if ((global.team_member_current_id).character_item_equipped != inventory_selected)
                {
                    (global.team_member_current_id).character_item_equipped = inventory_selected;
                }
                else
                {
                    (global.team_member_current_id).character_item_equipped = -1;
                }
            }
            else
            {
                //sonido no
            }
        }
        if (keyboard_check_pressed(global.dpad[0]) == true)
        {
            if (inventory_selected < inventory_itemsrow)
            {
                inventory_selected += ((inventory_itemsrow) * (inventory_rows - 1));
            }
            else
            {
                inventory_selected -= (inventory_itemsrow);
            }
        }
        if (keyboard_check_pressed(global.dpad[1]) == true)
        {
            if (inventory_selected > (global.inventory_current_maxitems - inventory_itemsrow - 1))
            {
                inventory_selected -= (inventory_itemsrow * (inventory_rows - 1));
            }
            else
            {
                inventory_selected += inventory_itemsrow;
            }
        }
        if (keyboard_check_pressed(global.dpad[2]) == true)
        {
            if (inventory_selected = 0)
            {
                inventory_selected = (global.inventory_current_maxitems - 1);
            }
            else
            {
                inventory_selected--;
            }
        }
        if (keyboard_check_pressed(global.dpad[3]) == true)
        {
            if (inventory_selected = global.inventory_current_maxitems - 1)
            {
                inventory_selected = 0;
            }
            else
            {
                inventory_selected++;
            }
        }
    }
    else
    {
        if ((keyboard_check_pressed(global.button[6]) == true) && (global.control == 1))
        {
            global.inventory = true;
            global.control = 0;
        }
    }
}
